package com.atmk.atmk.designMode.创建型.单例模式.饿汉式;
/*
* 静态常量(可能造成内存浪费)
* */
public class Singleton1 {
    //1、私有化构造器，外部不能new
    private Singleton1() {
    }

    //2、本类内部创建对象实例
    private static final Singleton1 instance1 = new Singleton1();

    //3、提供一个公有的静态方法，返回实例对象
    public static Singleton1 getInstance1() {
        return instance1;
    }

    public static void main(String[] args) {
        Singleton1 instance1 = Singleton1.getInstance1();
        Singleton1 instance2 = Singleton1.getInstance1();
        System.out.println(instance1 == instance2);
        System.out.println("instance1.hashCode="+instance1.hashCode());
        System.out.println("instance2.hashCode="+instance2.hashCode());
    }

}
